package com.chj.chuji.tijie01;

public class NNSequence {
	public static void main(String[] args) {
//		Scanner sc = new Scanner(System.in);
//		int n = sc.nextInt();

		int n = 6;
		int[] asc = new int[] { 7, 2, 3, 1, 5, 6 };

		int[] a = new int[n + 5];
		int[] e = new int[n + 5];
		int[] s = new int[n + 5];
		a[0] = 1;
		a[n + 1] = 1;
		for (int i = 1; i <= n; i++) {
			if (i <= asc.length) {
				a[i] = asc[i - 1];
			}
		}
		for (int i = 1; i <= n; i++) {
			e[i] = (a[i] > a[i - 1]) ? (e[i - 1] + 1) : 1;/// 以i结尾的最长子序列
		}
		for (int i = n; i >= 1; i--) {
			s[i] = (a[i] < a[i + 1]) ? (s[i + 1] + 1) : 1;/// 以i开始的最长子序列
		}
		int res = 1;
		for (int i = 1; i <= n; i++) {
			res = Math.max(e[i - 1] + 1, res);
			res = Math.max(s[i + 1] + 1, res);/// 找到当前最大的最长子序列
			if ((a[i + 1] - a[i - 1]) >= 2) {
				res = Math.max(res, e[i - 1] + s[i + 1] + 1);/// 当前i位置的后面和前面两个数字如果相差2就说明可以把i替换
			}

		}
		System.out.println(res);
	}
}
